//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateNews {
        private readonly INewsRepository _newsRepository;

        public CreateNews(INewsRepository newsRepository) {
            _newsRepository = newsRepository;
        }

        public void Execute(Guid userId, ICreateNewsCommand newsForm) {
            if (newsForm == null)
                throw new ArgumentNullException("newsForm");

            try {
                var news = newsForm.ConvertToEntity();
                _newsRepository.Create(news);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
